import { hotCateListApi } from '@/services/homeApi'
import { getCategoryListApi } from '@/services/categoryApi'
import storage from '@/utils/storage'

export const getHotCateListAction = () => async (dispatch, getState) => {
  // redux中的hotCateData数据存在则不去请求
  const hotCateData = getState().cate.hotCateData
  if (hotCateData.length == 0) {
    let ret = await hotCateListApi()
    // window.sessionStorage.setItem('hotcatedata', JSON.stringify(ret.data))
    storage().set('hotcatedata', ret.data)
    dispatch({ type: 'cate/hotCateData', payload: ret.data })
  }
}

// 分类列表
export const getCategoryListAction = () => async (dispatch, getState) => {
  const data = getState().cate.list
  if (!data.category) {
    let ret = await getCategoryListApi()
    dispatch({ type: 'cate/setCategoryList', payload: ret.data })
  }
}
